import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class TriangleCount {
    public static void main(String[] args) {
        int[] S = {3, 6, 7, 4}; //3467
        List<int[]> list = triangleCount(S);
        for (int i = 0; i < list.size(); i++) {
            System.out.println("三角形的个数 ：" + list.size());
            System.out.println(Arrays.toString(list.get(i)));
        }
    }
    public static List<int[]> triangleCount(int[] S) {
        //三角形最少三个元素
        if (S == null || S.length < 3) {
            return null;
        }
        List<int[]> result =new ArrayList<>();
        Arrays.sort(S);

       for(int i = S.length -1 ;i >=2 ; i--){
           int start = 0;
           int end = i-1;
           while (start < end){
               if (S[start]+S[end]>S[i]){
                   int[]int1 = new int[3];
                   int1[0] = S[start];
                   int1[1] = S[end];
                   int1[2] = S[i];
                   result.add(int1);
                   int a = start+1;
                   while (a<end){
                       int[] int2 =new int[3];
                       int2[0] =S[a];
                       int2[1] = S[end];
                       int2[2] = S[i];
                       result.add(int2);
                       a++;
                   }
                   end--;
               }else {
                   start++;
               }
           }
       }
       return result;
    }

}
